package Text_008;

import java.util.Scanner;

public class NumChage {

	public static void main(String[] args) {
		//转换罗马数字
		Scanner sca = new Scanner(System.in);
		String str;
		while(true) {
			System.out.println("请输入一个字符串：");
			 str = sca.next();
			boolean b = change(str);
			if(b) {
				break;
				}
			else {
				System.out.println("条件不符，请重新输入：");
				continue;
			}
		}
		//字符拼接
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<str.length();i++) {
			char c = str.charAt(i);
			int num = c - 48;
			sb.append(prin(num)+" ");
		}
		System.out.println(sb);
	}
	//查表法
	public static String prin(int num) {
		String[] Lu = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
		return Lu[num];
	}
	public static boolean change(String str ) {
		//判断字符串长度
		if(str.length()>9) {
			return false;
		}
		for(int i=0;i<str.length();i++) {
			char c = str.charAt(i);
			//判断是否是数字
			if(c>'9'||c<'0') {
				return false;
			}
		}
		return true;

	}

}
